import { Controller } from "../../mvc/core/Controller";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { PetEventName } from "../view/pet/PetEventName";
import { DataEvent } from "../events/DataEvent";
import { GameProxy } from "../mvc/GameProxy";
import { MsgManager } from "../manager/MsgManager";
import { Language } from "../../../extend/language/Language";
import { SoundManager } from "../../common/sound/SoundManager";
import { SoundTypeConst } from "../../common/sound/SoundTypeConst";
import { SPetInfo } from "../../../Message/Game/SPetInfo";
import { PetGrowthBlessWindow } from "../view/pet/PetGrowthBlessWindow";
import { PetSpiritBlessWindow } from "../view/pet/PetSpiritBlessWindow";
type int = number;
//class PetForgeController
    
    export  class PetForgeController extends Controller
    {
        constructor()
        {
            
            super();Dispatcher.addEventListener(EventName.PetRefreshGrowth, this.onPetRefreshGrowth);
            Dispatcher.addEventListener(EventName.PetRefreshGrowthSuccess, this.onPetRefreshGrowthSuccess);
            Dispatcher.addEventListener(EventName.PetStrengthenSpirit, this.onPetStrengthenSpirit);
            Dispatcher.addEventListener(EventName.PetStrengthenSpiritSuccess, this.onPetStrengthenSpiritSuccess);
            Dispatcher.addEventListener(PetEventName.PetOpenGrowthBlessWindow, this.onPetOpenGrowthBlessWindowHandler);
            Dispatcher.addEventListener(PetEventName.PetOpenSpiritBlessWindow, this.onPetOpenSpiritBlessWindowHandler);
            Dispatcher.addEventListener(EventName.PetUseBless, this.onPetUseBlessHandler);
            Dispatcher.addEventListener(EventName.PetUseBlessSuccess, this.onPetUseBlessSuccessHandler);
            Dispatcher.addEventListener(EventName.PetBatchUpgradeGrowth, this.onPetBatchUpgradeGrowthHandler);
            Dispatcher.addEventListener(EventName.PetBatchUpgradeGrowthSuccess, this.onPetBatchUpgradeGrowthSuccessHandler);
            Dispatcher.addEventListener(EventName.PetBatchUpgradeSpirit, this.onPetBatchUpgradeSpiritHandler);
            Dispatcher.addEventListener(EventName.PetBatchUpgradeSpiritSuccess, this.onPetBatchUpgradeSpiritSuccessHandler);
            return;
        }

        protected /* override */ initServer(): void
        {
            super.initServer();
            return;
        }

        public onPetRefreshGrowth(arg1: DataEvent): void
        {
            var loc1=arg1.data["uid"] as string;
            var loc2=arg1.data["materials"] as Array<any>;
            var loc3=arg1.data["isAutoBuy"] as Boolean;
            GameProxy.petProxy.refreshGrowth(loc1, loc2, loc3);
            if (cache.guide.guidePetRefresh) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.Guide_PetRefresh));
            }
            return;
        }

        public onPetRefreshGrowthSuccess(arg1: DataEvent): void
        {
            var loc1=new Map<any, any> /* flash.utils.Dictionary */();
            var loc2=arg1.data["success"] as Boolean;
            if (loc2) 
            {
                MsgManager.showRollTipsMsg(Language.getString(54413));
                SoundManager.instance.soundPlay(SoundTypeConst.ChengZhangS);
            }
            else 
            {
                MsgManager.showRollTipsMsg(Language.getString(54414));
                SoundManager.instance.soundPlay(SoundTypeConst.ChengZhangF);
            }
            return;
        }

        public onPetStrengthenSpirit(arg1: DataEvent): void
        {
            var loc1=arg1.data["uid"] as string;
            var loc2=arg1.data["materials"] as Array<any>;
            var loc3=arg1.data["isAutoBuy"] as Boolean;
            GameProxy.petProxy.strengthenSpirit(loc1, loc2, loc3);
            return;
        }

        public onPetStrengthenSpiritSuccess(arg1: DataEvent): void
        {
            var loc1=new Map<any, any> /* flash.utils.Dictionary */();
            this.petUid = arg1.data["uid"] as string;
            var loc2=arg1.data["success"] as Boolean;
            if (loc2) 
            {
                MsgManager.showRollTipsMsg(Language.getString(54415));
                SoundManager.instance.soundPlay(SoundTypeConst.LingXingS);
            }
            else 
            {
                MsgManager.showRollTipsMsg(Language.getString(54416));
                SoundManager.instance.soundPlay(SoundTypeConst.LingXingF);
            }
            return;
        }

        /* internal  */onPetOpenGrowthBlessWindowHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data["petInfo"] as SPetInfo;
            var loc2=arg1.data["blessLevel"] as int;
            if (this._growthBlessWindow == null) 
            {
                this._growthBlessWindow = new PetGrowthBlessWindow(loc1);
            }
            this._growthBlessWindow.blessLevel = loc2;
            this._growthBlessWindow.updateByPetInfo(loc1);
            this._growthBlessWindow.show();
            return;
        }

        /* internal  */onPetOpenSpiritBlessWindowHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data["petInfo"] as SPetInfo;
            var loc2=arg1.data["blessLevel"] as int;
            if (this._spiritBlessWindow == null) 
            {
                this._spiritBlessWindow = new PetSpiritBlessWindow(loc1);
            }
            this._spiritBlessWindow.blessLevel = loc2;
            this._spiritBlessWindow.updateByPetInfo(loc1);
            this._spiritBlessWindow.show();
            return;
        }

        /* internal  */onPetUseBlessHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data["uid"] as string;
            var loc2=arg1.data["isGrowth"] as Boolean;
            GameProxy.petProxy.usePetBless(loc1, loc2);
            return;
        }

        /* internal  */onPetUseBlessSuccessHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as Boolean;
            if (loc1) 
            {
                MsgManager.showRollTipsMsg(Language.getString(54417));
            }
            else 
            {
                MsgManager.showRollTipsMsg(Language.getString(54418));
            }
            return;
        }

        /* internal  */onPetBatchUpgradeGrowthHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data["uid"] as string;
            var loc2=arg1.data["isAutoBuy"] as Boolean;
            var loc3=arg1.data["num"] as int;
            var loc4=arg1.data["target"] as int;
            GameProxy.petProxy.refreshGrowthEx(loc1, loc2, loc3, loc4);
            return;
        }

        /* internal  */onPetBatchUpgradeGrowthSuccessHandler(arg1: DataEvent): void
        {
            MsgManager.showRollTipsMsg("提升成功");
            return;
        }

        /* internal  */onPetBatchUpgradeSpiritHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data["uid"] as string;
            var loc2=arg1.data["isAutoBuy"] as Boolean;
            var loc3=arg1.data["num"] as int;
            var loc4=arg1.data["target"] as int;
            GameProxy.petProxy.strengthenSpiritEx(loc1, loc2, loc3, loc4);
            return;
        }

        /* internal  */onPetBatchUpgradeSpiritSuccessHandler(arg1: DataEvent): void
        {
            MsgManager.showRollTipsMsg("提升成功");
            return;
        }

        public getShowGrowthBlessWindowPetUid(): string
        {
            var loc1=null;
            if (!(this._growthBlessWindow == null) && this._growthBlessWindow.isHide == false) 
            {
                if (this._growthBlessWindow.petInfo) 
                {
                    loc1 = this._growthBlessWindow.petInfo.uid;
                }
            }
            return loc1;
        }

        public getShowSpiritBlessWindowPetUid(): string
        {
            var loc1=null;
            if (!(this._spiritBlessWindow == null) && this._spiritBlessWindow.isHide == false) 
            {
                if (this._spiritBlessWindow.petInfo) 
                {
                    loc1 = this._spiritBlessWindow.petInfo.uid;
                }
            }
            return loc1;
        }

        private /* var */_growthBlessWindow: PetGrowthBlessWindow;

        private /* var */_spiritBlessWindow: PetSpiritBlessWindow;

        private /* var */petUid: string="";

        private /* var */_friendOnline: Boolean=false;

        private static /* var */toOpenTab: int=0;
    }

            PetForgeController.toOpenTab = 0;
        